package cn.iocoder.yudao.module.service.impl;

import cn.iocoder.yudao.module.VO.StudentVo;
import cn.iocoder.yudao.module.mapper.ScoreMapper;
import cn.iocoder.yudao.module.mapper.StudentMapper;
import cn.iocoder.yudao.module.pojo.Score;
import cn.iocoder.yudao.module.pojo.Student;
import cn.iocoder.yudao.module.service.StudentService;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@Service
@Validated
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    public Student getStudentById(Long id) {
        return studentMapper.getStudentById(id);
    }

    @Override
    public void saveStudent(StudentVo student) {

        
        Student student1 = new Student();
       // BeanUtils.copyProperties(student, student1);
        student1.setId(student.getId());
        student1.setName(student.getName());
        student1.setClassId(student.getClassId());
        studentMapper.insertStudent(student1);
    }

    @Override
    public void updateStudent(StudentVo student) {
        Student student1 = new Student();
        //BeanUtils.copyProperties(student, student1);
        student1.setId(student.getId());
        student1.setName(student.getName());
        student1.setClassId(student.getClassId());
        studentMapper.updateStudent(student1);
    }

    @Override
    public void deleteStudentById(Long id) {
        studentMapper.deleteStudentById(id);
    }

    @Override
    public List<Score> getStudentScoreByStudentId(Long id) {
        return scoreMapper.getScoreByStudentId(id);
    }

}
